package web.fabrimind.mwm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.mwm.domain.MaterialOutbound;
import web.fabrimind.mwm.service.IMaterialOutboundService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 物料出库Controller
 * 
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/mwm/outbound")
public class MaterialOutboundController extends BaseController
{
    @Autowired
    private IMaterialOutboundService materialOutboundService;

    /**
     * 查询物料出库列表
     */
    @PreAuthorize("@ss.hasPermi('mwm:outbound:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialOutbound materialOutbound)
    {
        startPage();
        List<MaterialOutbound> list = materialOutboundService.selectMaterialOutboundList(materialOutbound);
        return getDataTable(list);
    }

    /**
     * 导出物料出库列表
     */
    @PreAuthorize("@ss.hasPermi('mwm:outbound:export')")
    @Log(title = "物料出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialOutbound materialOutbound)
    {
        List<MaterialOutbound> list = materialOutboundService.selectMaterialOutboundList(materialOutbound);
        ExcelUtil<MaterialOutbound> util = new ExcelUtil<MaterialOutbound>(MaterialOutbound.class);
        util.exportExcel(response, list, "物料出库数据");
    }

    /**
     * 获取物料出库详细信息
     */
    @PreAuthorize("@ss.hasPermi('mwm:outbound:query')")
    @GetMapping(value = "/{outboundId}")
    public AjaxResult getInfo(@PathVariable("outboundId") Long outboundId)
    {
        return success(materialOutboundService.selectMaterialOutboundByOutboundId(outboundId));
    }

    /**
     * 新增物料出库
     */
    @PreAuthorize("@ss.hasPermi('mwm:outbound:add')")
    @Log(title = "物料出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialOutbound materialOutbound)
    {
        return toAjax(materialOutboundService.insertMaterialOutbound(materialOutbound));
    }

    /**
     * 修改物料出库
     */
    @PreAuthorize("@ss.hasPermi('mwm:outbound:edit')")
    @Log(title = "物料出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialOutbound materialOutbound)
    {
        return toAjax(materialOutboundService.updateMaterialOutbound(materialOutbound));
    }

    /**
     * 删除物料出库
     */
    @PreAuthorize("@ss.hasPermi('mwm:outbound:remove')")
    @Log(title = "物料出库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{outboundIds}")
    public AjaxResult remove(@PathVariable Long[] outboundIds)
    {
        return toAjax(materialOutboundService.deleteMaterialOutboundByOutboundIds(outboundIds));
    }
}
